<?php
    session_start();
    if(!isset($_SESSION['username'])){
                header("Location: index.php");
                $_SESSION['log']=1;
    }
    else{
    if(!isset($_POST['add'])){
        echo '<form action="display.php" method="POST">';
        include 'config.php';
        $proxy = new SoapClient($config['SOAPLocation']);
        $sessionId = $proxy->login($config['SOAPUser'],$config['SOAPKey']);
        $prod = $proxy->call($sessionId,'catalog_product.list', 'default');
        $_SESSION['products']=$prod;
        $proxy->endSession($sessionId);
        $i=0;
        foreach($prod as $p){
            echo "<input type='checkbox' name='check_$i' value='ON' />";
            echo $p['name'];
            echo ";".$p['websites'].";";
            echo $p['sku']."<br>";

            $i++;
        }
        echo '<input type="submit" value="Add these items to Store" name="add" />';
        echo '</form>';
    }
    else{
        $i=0;
        $stored_prod;
        foreach($_SESSION['products'] as $p){
            if($_POST["check_$i"]=='ON'){
                //echo $p['name']." ".$p['sku']."<br>";
                $stored_prod[$i]=$p;
                $i++;
            }
        }
        $_SESSION['stored_prod']=$stored_prod;
        $URL="priceSet.php";

        header ("Location: $URL");
        echo "Added!";

    }
    
?>
    

<?php } ?>